extends Node2D

@onready var tile_map:TileMap = $TileMap
@onready var camera:Camera2D = $Player/Camera2D
@onready var player:CharacterBody2D = $Player


func _ready() -> void:
	var used := tile_map.get_used_rect().grow(-1)
	var tile_size := tile_map.tile_set.tile_size

	camera.limit_left = used.position.x * tile_size.x
	camera.limit_right = used.end.x * tile_size.x
	camera.limit_top = used.position.y * tile_size.y
	camera.limit_bottom = used.end.y * tile_size.y
	camera.reset_smoothing()


func update_player(pos:Vector2, direction:Player.Direction):
	player.global_position = pos
	player.fall_from_y = pos.y
	player.direction = direction
	camera.reset_smoothing()
	camera.force_update_scroll()
